package com.rem.cloudalibaba.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


/**
 * @author Rem
 * @date 2021/7/14
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> implements Serializable {

    /**
     * 0:成功  其他:失败
     */
    private Integer code;

    /**
     * 消息
     */
    private String message;

    /**
     * 数据
     */
    private T data;

    public CommonResult(Integer code, String message) {
        this(code, message, null);
    }

    /**
     * 静态方法
     *
     * @return
     */
    public static CommonResult response(Integer code, String message, Object data) {
        return new CommonResult(code, message, data);
    }

    public static CommonResult response(Integer code, String message) {
        return new CommonResult(code, message);
    }

    public static CommonResult ok(Object data) {
        return new CommonResult(0, "处理成功", data);
    }

    public static CommonResult error(Object data) {
        return new CommonResult(99, "处理失败", data);
    }

    public static CommonResult ok() {
        return new CommonResult(0, "处理成功");
    }

    public static CommonResult error() {
        return new CommonResult(99, "处理失败");
    }

}
